// pages/epi_4/fileOperate/fileOperateWork.js
Page({
    data: {
      imagePath: null,
      download_imagePath: null,
      onlineImagepath: null,
      my_stu_id: '',
      stu_id: ''
    },
    
    choosePhoto: function(){
      var that = this
      wx.chooseMedia({
        count:9,
        mediaType: ['image'],
        sourceType: ['album', 'camera'],
        success (res){
          that.setData({
            imagePath: res.tempFiles[0].tempFilePath
          })
        }
      })
    },
  
    uploadPhoto: function(){
      var that = this
      wx.uploadFile({
        filePath: that.data.imagePath,
        name: that.data.my_stu_id,
        url: 'http://47.109.143.70/for224/upload_photo',
        success(res){
          console.log(res)
        },
        fail(res){
            console.log(res)
        }
      })
    },
  
    downloadPhoto: function(){
      var tar_url = `http://47.109.143.70/src/${this.data.stu_id}.png`
      var that = this
      wx.downloadFile({
        url: tar_url,
        success(res){
            if (res.statusCode===200){
                wx.showToast({
                  title: '下载成功',
                })
                that.setData({
                    download_imagePath: res.tempFilePath
                })
            }
        },
        fail(res){
            console.log(res)
            wx.showToast({
              title: '下载失败',
              icon: 'none'
            })
        }
      })
    },
  
    previewOnlinephoto: function(){
      var url = `http://47.109.143.70/src/${this.data.stu_id}.png`
      console.log(url)
      wx.previewImage({
          urls: [
              url
          ]
      })
    }
  })